package cz.hackathon;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import cz.hackathon.core.Controller;
import cz.hackathon.rateit.model.Action;
import cz.hackathon.rateit.model.Category;

public class TabActivity extends android.app.TabActivity {
	
	@Override	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		setContentView(R.layout.tab_layout);
//		
		Action action = (Action) getIntent().getSerializableExtra("Action");
//		
//		TabHost tabHost = (TabHost) findViewById(R.id.tab_content);
//		tabHost.setup();
//		
//		TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
//		TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
//		

//		Intent intent2 = new Intent(getBaseContext(), ItemsActivity.class);
//		intent2.putExtra("Action", action);
//		
//		firstTabSpec.setIndicator("First Tab Name").setContent(intent);
//		secondTabSpec.setIndicator("Second Tab Name").setContent(intent2);
//		
//		tabHost.addTab(firstTabSpec);
//		tabHost.addTab(secondTabSpec);	
		TabHost t = getTabHost();
		for(final Category c : Controller.getCategories(action) ){
//			ItemsActivity.adapter.notifyDataSetChanged();
			final Intent intent = new Intent(getBaseContext(), ItemsActivity.class);
			intent.putExtra("Category", c);
			intent.putExtra("Action", action);
			intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			final TabSpec tab = t.newTabSpec("td");
			tab.setIndicator(c.getName());
            tab.setContent(intent);
			t.addTab(tab);
			
			t.setOnTabChangedListener(new OnTabChangeListener() {
				
				@Override
				public void onTabChanged(String tabId) {
										
				}
			});
		}
		
		
	    
	    
	    
	    setContentView(t);
	}
	
	

}
